package com.cy.shiro.controller;

import com.cy.shiro.pojo.SysResources;
import com.cy.shiro.pojo.SysUser;
import com.cy.shiro.service.SysResourcesService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
public class BaseController {

//    @RequestMapping("/{page}")
//    public String page(@PathVariable String page){
//        return page;
//    }

    @Autowired
    private SysResourcesService sysResourcesService;

    public void sysResources(String title, String active, Model model){
        Subject subject = SecurityUtils.getSubject();
        SysUser user = (SysUser) subject.getPrincipal();// 获取当前登陆用户
        List<SysResources> sysResources = sysResourcesService.resourcesList(user.getId());
        model.addAttribute("sysResources", sysResources);
        model.addAttribute("title", title);
        model.addAttribute("active", active);
    }
}
